package com.yanqu.road.server.cmd.activity.langyabang;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LangYaBangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.langyabang.LangYaBangModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_LANG_YA_BANG_CASE_GAME_DEAL,desc = "琅琊榜金陵风云操作")
public class LangYaBangCaseGameDealCmd extends AbstractCommand {
    private int activityId;
    private int chooseId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        LangYaBangProto.LangYaBangUserDealCaseGameReqMsg langYaBangUserDealCaseGameReqMsg = LangYaBangProto.LangYaBangUserDealCaseGameReqMsg.parseFrom(packet.getBytes());
        activityId = langYaBangUserDealCaseGameReqMsg.getActivityId();
        chooseId = langYaBangUserDealCaseGameReqMsg.getChooseId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(LangYaBangModule.class).operateCaseGameCard(activityId,chooseId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            LangYaBangProto.LangYaBangUserDealCaseGameRespMsg.Builder builder = LangYaBangProto.LangYaBangUserDealCaseGameRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_LANG_YA_BANG_CASE_GAME_DEAL,builder);
        }
    }
}
